.TH std::future_error 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::future_error \- std::future_error

.SH Synopsis
   Defined in header <future>
   class future_error;         \fI(since C++11)\fP

   The class std::future_error defines an exception object that is thrown on failure by
   the functions in the thread library that deal with asynchronous execution and shared
   states (std::future, std::promise, etc). Similar to std::system_error, this
   exception carries an error code compatible with std::error_code.

   std-future error-inheritance.svg

                                   Inheritance diagram

.SH Member functions

   constructor   creates a std::future_error object
                 \fI(public member function)\fP
   operator=     replaces the std::future_error object
                 \fI(public member function)\fP
   code          returns the error code
                 \fI(public member function)\fP
   what          returns the explanatory string specific to the error code
                 \fI(public member function)\fP

Inherited from std::logic_error

Inherited from std::exception

.SH Member functions

   destructor   destroys the exception object
   \fB[virtual]\fP    \fI(virtual public member function of std::exception)\fP
   what         returns an explanatory string
   \fB[virtual]\fP    \fI(virtual public member function of std::exception)\fP

.SH Example


// Run this code

 #include <future>
 #include <iostream>

 int main()
 {
     std::future<int> empty;
     try
     {
         int n = empty.get(); // The behavior is undefined, but
                              // some implementations throw std::future_error
     }
     catch (const std::future_error& e)
     {
         std::cout << "Caught a future_error with code \\"" << e.code()
                   << "\\"\\nMessage: \\"" << e.what() << "\\"\\n";
     }
 }

.SH Possible output:

 Caught a future_error with code "future:3"
 Message: "No associated state"

.SH See also

   future_errc identifies the future error codes
   \fI(C++11)\fP     \fI(enum)\fP
